﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Text;

namespace Axis.Web.Views.Research
{
    public partial class ResearchList : System.Web.UI.Page
    {
        ResearchUI researchUI = new ResearchUI();
        protected void Page_Load(object sender, EventArgs e)
        {
            var ID = 0;
            if (Page.RouteData.Values["ID"] != null)
                ID = Convert.ToInt32(Page.RouteData.Values["ID"]);

            if (Request.QueryString["ID"] != null)
            {
                ID = Convert.ToInt32(Request.QueryString["ID"]);
                var list = researchUI.GetProject(string.Format("<InputValue ID=\"{0}\" Context=\"ByProjectID\"/>", ID));
                if (list != null)
                {
                    if (list.Count > 0)
                    {
                        var item = list[0];
                        string Pattent = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
                + "<meta name=\"description\" content=\"{0}.\" />"
                + "<meta name=\"keywords\" content=\"{1}\" />  "
                 + "<meta property=\"fb:admins\" content=\"100000866764550113\" />"
                    + "<meta  property=\"og:image\" content =\"{2}\" itemprop=\"thumbnailUrl\"/>  ";
                        string description = "";
                        if (item.Description != null)
                        {
                            Regex regex = new Regex("(<.*?>\\s*)+", RegexOptions.Singleline);
                            description = regex.Replace(item.Description, " ").Trim();
                        }
                        HeaderPage.Text = string.Format(Pattent, description, item.Name, "http://6sao.vn" + item.Image1);
                        TitlePage.Text = item.Name + "| Trúng thưởng | Quà tặng miễn phí | Khảo sát trực tuyến";

                    }
                }
            }
            StringBuilder scriptServerConfig = new StringBuilder();
            scriptServerConfig.AppendFormat("var ProjectID={0};\n", ID.ToString().Trim());
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "ServerConfig",
                                    scriptServerConfig.ToString(), true);
            if (!IsPostBack)
            {
                int PageIndex = 1;
                if (Request.QueryString["PageIndex"] != null)
                {
                    PageIndex = Convert.ToInt32(Request.QueryString["PageIndex"]);
                }

                ltrResearchList.Text = researchUI.GetProjectList(PageIndex, "10");
                if (researchUI.GetTotalPage() > 1)
                {
                    if (researchUI.GetTotalPage() > PageIndex)
                    {
                        PageIndex = PageIndex + 1;
                    }
                    else
                    {
                        PageIndex = PageIndex - 1;
                    }
                    ltrMore.Text = string.Format("<a href='../../Views/Research/ResearchList.aspx?PageIndex={0}' class='Research_List_More'><img src='Css/img/more_list.png' /></a>", PageIndex);
                }



            }
        }
    }
}